package com.premedsidekick;

import java.io.FileInputStream;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;

public class ExtraCurricularRequirements extends Activity {

	Resources res;
	SharedPreferences preferences;
	SharedPreferences.Editor editor;
	CheckBox clinic;
	CheckBox physician;
	CheckBox research;
	CheckBox service;
	
	boolean b_clinic, b_physician, b_research, b_service;
	String filename;
	byte[] buffer;
	
	FileInputStream fos;
		
	public OnClickListener ClinicCheck = new OnClickListener() {
		public void onClick(View view) {
			if (!clinic.isChecked()) {
				editor.putBoolean("clinic_check", false);
				clinic.setChecked(false);
			}
			else {
				editor.putBoolean("clinic_check", true);
				clinic.setChecked(true);
			}
			editor.commit();
		}
	};
	public OnClickListener PhysicianCheck = new OnClickListener() {
		public void onClick(View view) {
			if (!physician.isChecked()) {
				editor.putBoolean("physician_check", false);
				physician.setChecked(false);
			}
			else {
				editor.putBoolean("physician_check", true);
				physician.setChecked(true);
			}
			editor.commit();
		}
	};
	public OnClickListener ResearchCheck = new OnClickListener() {
		public void onClick(View view) {
			if (!research.isChecked()) {
				editor.putBoolean("research_check", false);
				research.setChecked(false);
			}
			else {
				editor.putBoolean("research_check", true);
				research.setChecked(true);
			}
			editor.commit();
		}
	};
	public OnClickListener ServiceCheck = new OnClickListener() {
		public void onClick(View view) {
			if (!service.isChecked()) {
				editor.putBoolean("service_check", false);
				service.setChecked(false);
			}
			else {
				editor.putBoolean("service_check", true);
				service.setChecked(true);
			}
			editor.commit();
		}
	};
	
	public void onCreate (Bundle bundle) {
		super.onCreate (bundle);
		setContentView (R.layout.extra_curricular_requirements);
		filename = "extra_file";
		
		preferences = getSharedPreferences(filename, 0);
		editor = preferences.edit();
		b_clinic = preferences.getBoolean("clinic_check", false);
		b_physician = preferences.getBoolean("physician_check", false);
		b_research = preferences.getBoolean("research_check", false);
		b_service = preferences.getBoolean("service_check", false);
		
		//buffer = new byte[1];
		
		/*
		try {
			fos = openFileInput(filename);
		} catch (Exception e) {
			// Handle exception here later
		}
		try { 
			fos.read(buffer);
		} catch (Exception e) {
			// handle this later again
		}
		*/
		clinic = (CheckBox) findViewById (R.id.extra_requirements_clinical_checkbox); 
		clinic.setOnClickListener(ClinicCheck);
		// must handle logic for a checked box
		if (b_clinic)
			clinic.setChecked(true);
		
		physician = (CheckBox) findViewById (R.id.extra_requirements_physician_checkbox); 
		physician.setOnClickListener(PhysicianCheck);
		if (b_physician)
			physician.setChecked(true);
		
		research = (CheckBox) findViewById (R.id.extra_requirements_research_checkbox); 
		research.setOnClickListener(ResearchCheck);
		if (b_research)
			research.setChecked(true);
		
		service = (CheckBox) findViewById (R.id.extra_requirements_community_service_checkbox); 
		service.setOnClickListener(ServiceCheck);
		if (b_service)
			service.setChecked(true);
	} 
}

